package com.bbx.api.sdk.model.passanger.Return.CarType;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @Path com.bbx.api.sdk.model.passanger.Return.CarType.CarData.java
 * @Author 严旭文
 * @Date 2016-10-19 下午4:35:51
 * @Company 蓝海（福建）信息技术有限公司
 * @Description
 */
public class CarData {
	// 通用车型，如市内的打表，拼车，包车单程，货物
	public static final String CAR_CLASS_ID = "allcarclass";

	public int business_type;
	public int car_level;
	public int car_seats;
	public int car_type;
	public String car_class_id;
	public double default_miles;
	public double default_minutes;
	public String line_id;
	public double mile_price;
	public double combo_price;
	public double time_price;
	public String class_name;
	public String car_name;
	public String class_url;
	public int calc_type;// 0打表 1计费
	public String price_id;
	public double schedule_price;// 感谢费，城内才有
	/*------------------------夜间模式--城内才有-----------------------------*/
	public int night_enable;// 判断是否有夜间，1有，2没有
	public double night_combo_price;// 等同于combo_price
	public double night_default_miles;// 等同于default_miles
	public double night_default_minutes;
	public double night_mile_price;
	public double night_schedule_price;// 感谢费
	public double night_time_price;
	public long night_time_start;
	public long night_time_end;

	public double getComboPrice(long time) {
		return getCartTypeNight(time) ? night_combo_price : combo_price;
	}

	public double getDefaultMiles(long time) {
		return getCartTypeNight(time) ? night_default_miles : default_miles;
	}

	public double getDefaultMinutes(long time) {
		return getCartTypeNight(time) ? night_default_minutes : default_minutes;
	}

	public double getMilePrice(long time) {
		return getCartTypeNight(time) ? night_mile_price : mile_price;
	}

	public double getTimePrice(long time) {
		return getCartTypeNight(time) ? night_time_price : time_price;
	}

	public double getSchedulePrice(long time) {
		return getCartTypeNight(time) ? night_schedule_price : schedule_price;
	}
    public long getNightStartTime(){
    	return night_time_start;
    }
    public long getNightEndTime(){
    	return night_time_end;
    }
	/**
	 * 判断是否是夜间
	 */
	public boolean getCartTypeNight(long time) {
		  Calendar calendar = Calendar.getInstance(); 
		  calendar.setTimeInMillis(time);
		  int hour=calendar.get(Calendar.HOUR_OF_DAY);;
		  int minute=calendar.get(Calendar.MINUTE);
		  int second=calendar.get(Calendar.SECOND);
		long nowtime=(second+(minute*60)+(hour*3600));
		long time24=(24*3600);
		if(night_enable==1){
			//当天
			if(nowtime>=night_time_start&&nowtime<=night_time_end){
				return true;
			}
			//跨天
			else if(night_time_start>night_time_end){
				if(nowtime>=night_time_start&&nowtime<=time24){
					return true;
				}else if(nowtime>=0&&nowtime<=night_time_end){
					return true;
				}
			}
		}
		return false;
	}
	/**
	 * 转换为时间戳
	 */
	public static long onDate_Long(String time) {
		Date date = null;
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm");
		try {
			date = sdf.parse(time);
		} catch (ParseException e) {
		}
		return date.getTime();
	}
}
